<?php $this->renderPartial('/admin/menu/users', array('role' => $role));?>
<h4><i class="fa fa-user"></i> <?php echo $user['user_fullname']; ?></h4><hr>
<?php 
foreach(Yii::app()->user->getFlashes() as $key => $message){
	echo '<div class="'.$key.'"><p>'.$message."</p></div>\n";
}
?>
<form role="form" id="my-account" class="form-horizontal" method="post" autocomplete="off">

<div class="form-group">
	<label class="col-sm-2 control-label" for="user_role"><?php echo Yii::t('helpdesk','Group'); ?></label>
    <div class="col-sm-3">
    <select class="form-control" id="user_role" name="user_role" <?php if(isset($user['roles']) && $user['roles'] == '1'): ?>disabled<?php endif; ?> onChange="showDepts(this.value);">
    	<option value="3"><?php echo Yii::t('helpdesk','Members'); ?></option>
        <option value="2" <?php if(isset($user['roles']) && ($user['roles'] == '2' || $user['roles'] == '1')): ?>selected<?php endif; ?>><?php echo Yii::t('helpdesk','Staffs'); ?></option>
    </select>
    </div>
</div>
<div class="form-group notify" <?php if(isset($user['roles']) && ($user['roles'] == '1' || $user['roles'] == '2')): ?>style="display:none;"<?php endif; ?>>
	<label class="col-sm-2 control-label" for="user_role"><?php echo Yii::t('helpdesk','Receive notification from ticket subject'); ?></label>
    
    <!--
     <div class="col-sm-3">
     	<?php foreach($arrDepts as $R): ?>
            <div class="checkbox <?php echo ($R['category_level'] > 0)?'col-sm-offset-2':null; ?>">
            <label>
              <input type="checkbox" name="dept[]" value="<?php echo $R['category_id']; ?>" <?php if( isset($user['category_id']) && in_array($R['category_id'], $user['category_id'])):?>checked=""<?php endif; ?>> <?php echo $R['category_name']; ?>
            </label>
            </div>
        <?php endforeach; ?>
     </div>
     -->   
    
    <div class="col-sm-3">
    <select id="cats" name="cats[]" multiple="" class="form-control" required size="<?php echo count($arrDepts); ?>">
		<?php foreach($arrDepts as $R): ?>
        <option value="<?php echo $R['category_id']; ?>" <?php if( isset($user['category_id']) && in_array($R['category_id'], $user['category_id'])):?>selected=""<?php endif; ?>>
			<?php for($i=0; $i<$R['category_level']; $i++): echo '&nbsp;&nbsp;&nbsp;'; endfor; ?>
			<?php echo $R['category_name']; ?>
       	</option>
        <?php endforeach; ?>
    </select>
    </div>
</div>

<hr>
<div class="form-group">
	<label class="col-sm-2 control-label" for="user_fullname"><?php echo Yii::t('helpdesk','Full Name'); ?> <span class="red">*</span></label>
    <div class="col-sm-3">
	<input type="text" id="user_fullname" name="user[user_fullname]" class="form-control"  value="<?php echo $user['user_fullname']; ?>" required="" maxlength="128">
    </div>
</div>
<div class="form-group">
	<label class="col-sm-2 control-label" for="user_email"><?php echo Yii::t('helpdesk','Email'); ?> <span class="red">*</span></label>
    <div class="col-sm-3">
	<input type="email" id="user_email" name="user[user_email]" class="form-control" value="<?php echo $user['user_email']; ?>"  required="" maxlength="128">
    </div>
</div>
<div class="form-group">
	<label class="col-sm-2 control-label" for="address"><?php echo Yii::t('helpdesk','Address'); ?></label>
    <div class="col-sm-3">
	<input type="text" id="address" name="address" class="form-control" value="<?php echo $profile['profile_address']; ?>"  maxlength="128">
	</div>
</div>
<div class="form-group">
	<label class="col-sm-2 control-label" for="phone"><?php echo Yii::t('helpdesk','Phone'); ?></label>
    <div class="col-sm-3">
	<input type="text" id="phone" name="phone" class="form-control" value="<?php echo $profile['profile_phone']; ?>"  maxlength="50">
	</div>
</div>
<div class="form-group">
	<label class="col-sm-2 control-label" for="user_password"><?php echo Yii::t('helpdesk','Password'); ?></label>
    <div class="col-sm-3">
	<input type="password" placeholder="<?php echo Yii::t('helpdesk','Minimum'); ?> 5 <?php echo Yii::t('helpdesk','characters'); ?>" value="" id="user_password" name="user_password" class="form-control" autocomplete="off" maxlength="128">
    </div>
</div>
<div class="form-group">
	<label class="col-sm-2 control-label" for="re_password"><?php echo Yii::t('helpdesk','Retype password'); ?></label>
    <div class="col-sm-3">
	<input type="password" placeholder="<?php echo Yii::t('helpdesk','Minimum'); ?> 5 <?php echo Yii::t('helpdesk','characters'); ?>" value="" id="re_password" name="re_password" class="form-control" autocomplete="off" maxlength="128">
    </div>
</div>
<div class="form-group">
	<div class="col-sm-offset-2 col-sm-6">
   		<span style="color:red; font-style:italic; font-size:12px;"><?php echo Yii::t('helpdesk','Leave password blank if dont want to change'); ?></span>
	</div>
</div>

<div class="form-group">
	<div class="col-sm-offset-2 col-sm-6">
	<div class="checkbox">
    <label>
      <input type="checkbox" <?php if(!empty($profile['profile_allow_notify'])):?>checked=""<?php endif; ?> value="1" name="notification"> <?php echo Yii::t('helpdesk','Receive email notification from helpdesk?'); ?> [<i class="fa fa-question tt" title="<?php echo Yii::t('helpdesk', 'Uncheck if you don\'t want to receive notification from helpdesk'); ?>"></i>]
    </label>
	</div>
	</div>
</div>

<div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <input type="hidden" name="user_id" value="<?php echo $user['user_id']; ?>">
      <input type="submit" class="btn btn-primary btn-large" value="<?php echo Yii::t('helpdesk','Update'); ?>">
    </div>
</div>
</form>
<script type="text/javascript">
	$(document).ready(function(){
		showDepts($('#user_role').val());
		$('#my-account').validate({
			rules: {
				user_password: {
					noSpace: true,
					minlength: 5
				},
				re_password: {
					equalTo: "#user_password"
				}
			}
		});
		
		$.validator.addMethod("noSpace", function(value, element) {
			return (value.indexOf(" ") == -1) || (value.indexOf(" ") < 0 && value != ""); 
		}, "this field requires no space");
	});
	function showDepts(roleId){
		if(roleId == '1' || roleId == '2') {
			$('.notify').show();	
		} else {
			$('.notify').hide();	
		}
	}
</script>